package com.authsphere.security.authorization;

import com.authsphere.security.token.common.AccessToken;
import org.springframework.security.authentication.AbstractAuthenticationToken;
import org.springframework.security.core.Authentication;

import java.io.Serial;

/**
 * @program: AuthSphere
 * @description:
 * @author: YuKai Fan
 * @create: 2025/3/13 10:23
 **/
public class AuthorizationAuthenticationToken extends AbstractAuthenticationToken {

    @Serial
    private static final long serialVersionUID = 2690331482065523006L;
    private AccessToken accessToken;

    private Authentication storedAuthentication;
    private AuthorizationRequest authorizationRequest;

    public AuthorizationAuthenticationToken(AccessToken accessToken, AuthorizationRequest authorizationRequest) {
        super(null);
        this.accessToken = accessToken;
        this.authorizationRequest = authorizationRequest;
        setAuthenticated(false);
    }

    public AuthorizationAuthenticationToken(AccessToken accessToken,  Authentication storedAuthentication) {
        super(null);
        this.accessToken = accessToken;
        this.storedAuthentication = storedAuthentication;
        setAuthenticated(true);
    }

    @Override
    public AuthorizationRequest getCredentials() {
        return authorizationRequest;
    }

    @Override
    public AccessToken getPrincipal() {
        return accessToken;
    }

    public void setAccessToken(AccessToken accessToken) {
        this.accessToken = accessToken;
    }

    public Authentication getStoredAuthentication() {
        return storedAuthentication;
    }

    public void setStoredAuthentication(Authentication storedAuthentication) {
        this.storedAuthentication = storedAuthentication;
    }
}
